#include <cmath>
#include "GameObject.h"
#include "NativeTimeModel.h"
//////////////////////////////////////////////////////////////////
GameObject::GameObject()
{
	m_fPosX = 0;
	m_fPosY = 0;
	m_fPosZ = 0;
	return;
}
//////////////////////////////////////////////////////////////////
GameObject::GameObject(float x, float y, float z)
:m_fPosX(x), m_fPosY(y), m_fPosZ(z)
{
	return;
}
//////////////////////////////////////////////////////////////////
void GameObject::moveBy(float fdX, float fdY, float fdZ)
{
	m_fPosX+=fdX;
	m_fPosY+=fdY;
	m_fPosZ+=fdZ;
	return;
}
//////////////////////////////////////////////////////////////////
float GameObject::distanceFromOrigin()
{
	return sqrt(m_fPosX*m_fPosX+m_fPosY*m_fPosY+m_fPosZ+m_fPosZ);
}
//////////////////////////////////////////////////////////////////
void GameObject::update(NativeTimeModel *ntm)
{
	float fTotalSeconds = 0;
	float x = 0;
	float y = 0;
	float z = 0;
	float fLenght = 0;

	fTotalSeconds = (float)(ntm->m_iSecond+ntm->m_iMinute*60+ntm->m_iHour*3600+
		                  ntm->m_iDay*86400);
	
	//normalize velocity
	fLenght = sqrt(m_fVelX*m_fVelX+m_fVelY*m_fVelY+m_fVelZ*m_fVelZ);
	x = m_fVelX/fLenght;
	y = m_fVelY/fLenght;
	z = m_fVelZ/fLenght;

	m_fPosX += x*fTotalSeconds;
	m_fPosY += y*fTotalSeconds;
	m_fPosZ += z*fTotalSeconds;
	return;
}
//////////////////////////////////////////////////////////////////
void GameObject::setVel(float fX, float fY, float fZ)
{
	m_fVelX = fX;
	m_fVelY = fY;
	m_fVelZ = fZ;
	return;
}
